package com.yuyuan.blog.service.impl;


import com.yuyuan.blog.domain.po.BlogAgreement;
import com.yuyuan.blog.domain.po.BlogDaily;
import com.yuyuan.blog.domain.po.BlogDeal;
import com.yuyuan.blog.domain.po.BlogPractice;
import com.yuyuan.blog.mapper.AgreementBlogMapper;
import com.yuyuan.blog.mapper.DailyBlogMapper;
import com.yuyuan.blog.mapper.DealBlogMapper;
import com.yuyuan.blog.mapper.PracticeBlogMapper;
import com.yuyuan.blog.service.IMyBlogService;
import com.yuyuan.common.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/29
 */
@Slf4j
@Service
public class MyBlogServiceImpl implements IMyBlogService {

    @Autowired
    private AgreementBlogMapper agreementBlogMapper;

    @Autowired
    private DealBlogMapper dealBlogMapper;

    @Autowired
    private PracticeBlogMapper practiceBlogMapper;

    @Autowired
    private DailyBlogMapper dailyBlogMapper;

    @Override
    public Result getUserAgrees(Short blogType, Long userId, Long startId) {
        return null;
    }

    @Override
    public Result getUserDailies(Long userId, Long startId) {
        return null;
    }

    @Override
    public Result getUserDeals(Long userId, Long startId) {
        return null;
    }

    @Override
    public Result getUserPractices(Long userId, Long startId) {
        return null;
    }

    /**
     * 点击量Redis键后缀
     */
    public Map<Integer,String> clickMap = new HashMap<>();
    {
        clickMap.put(0,"daily:");
        clickMap.put(1,"deal:");
        clickMap.put(2,"practice");
        clickMap.put(3,"agreement");
    }

    @Override
    public Result getHotBlog(Integer blogType) {
        // TODO 暂时只设计0的情况 其他情况无定时器功能
        if (blogType == 0){
            BlogDaily blogDaily = dailyBlogMapper.queryHotBlog();
            blogDaily.handlerImgs();
            return Result.ok(blogDaily);
        } else if (blogType == 1){
            BlogDeal blogDeal = dealBlogMapper.queryHotBlog();
            blogDeal.handlerImgs();
            return Result.ok(blogDeal);
        } else if (blogType == 2){
            BlogPractice blogPractice = practiceBlogMapper.queryHotBlog();
            blogPractice.handlerImgs();
            return Result.ok(blogPractice);
        } else if (blogType == 3) {
            BlogAgreement blogAgreement = agreementBlogMapper.queryHotBlog();
            blogAgreement.handlerImgs();
            return Result.ok(blogAgreement);
        }
        return Result.ok();
    }
}
